package liyan.shi.springboot.controller;

import liyan.shi.springboot.exception.UserNotExistException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

import java.util.Arrays;
import java.util.Map;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam("user") String user) {
        if("aaa".equals(user)){
            throw new UserNotExistException();
        }
        return "Hello World";
    }

    /**
     * 查询一些数据在页面展示
     *
     * @param map
     * @return java.lang.String
     * @author yourname
     * @date 2018/10/28 19:04
     */
    @RequestMapping("/success")
    public String success(Map<String, Object> map) {
        map.put("hello", "<h1>Thymeleaf</h1>");
        map.put("users", Arrays.asList("小明", "小李", "小杰", "小王八蛋"));
        return "success";
    }

//    @RequestMapping({"/", "/index.html"})
//    public String index(){
//        return "login";
//    }
}
